<?php
class xhtml extends parent_class
{
	public $template="default";
	
	public $title="";
	public $keywords="";
	
	public $refresh=array("page" => "", "time" => "3");
	
	protected $script=array();
	protected $style=array();
	
	
	public function __construct($template="")
	{
		if (trim($template)<>"")
		{
			$this->template=$template;
		}
		$this->style[]=$GLOBALS["home_url"]."style/style.css";
	}
	
	public function __get($name)
	{
		return $this->name;
	}
	
	public function __set($name,$value)
	{
		switch (strtolower($name))
		{
			default:
				$this->name=$value;
			break;
			case "add_script":
				$this->script[]=$value;
			break;
			case "add_style":
				$this->style[]=$value;
			break;
			case "refresh_page":
				$this->refresh["page"]=$value;
			break;
			}
	}
	
	public function return_head()
	{
		$str_out="<?xml version=\"1.0\" encoding=\"windows-1251\"?>\n".
			"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n".
			"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"ru\">\n".
			"<head>\n";
		if (!empty($this->title))
		{
			$str_out.="<title>".$this->title."</title>\n";
		}
		if (!empty($this->keywords))
		{
			$str_out.="<meta name=\"keywords\" content=\"".$this->keywords."\" />\n";
		}
		if ($this->style)
		{
			foreach($this->style as $style)
			{
				$str_out.="<link rel=\"stylesheet\" href=\"".$style."\" type=\"text/css\" />\n";
			}
		}
		if ($this->script)
		{
			foreach($this->script as $script)
			{
				$str_out.="<script type=\"text/javascript\" src=\"".$script."\"></script>\n";
			}
		}
		if (!empty($this->refresh["page"]))
		{
			$str_out.="<meta http-equiv=\"refresh\" content=\"".intval($this->refresh["time"])."; url=".$this->refresh["page"]."\" />\n";
		}
		$str_out.="</head>\n";
		return $str_out;
	}
	public function makepage($page="")
	{
		print($this->return_head());
		$this->makebody($page);
	}
	
	
	public function makebody($page="")
	{
		if (file_exists($GLOBALS["xhtml_dir"]."/".$this->template."/header.inc.php"))
		{
			include($GLOBALS["xhtml_dir"]."/".$this->template."/header.inc.php");
		}
		else
		{
			$this->error(5);
		}
		if (file_exists($GLOBALS["xhtml_dir"]."/".$this->template."/#".$page.".inc.php"))
		{
			include($GLOBALS["xhtml_dir"]."/".$this->template."/#".$page.".inc.php");
		}
		if (file_exists($GLOBALS["xhtml_dir"]."/".$this->template."/footer.inc.php"))
		{
			include($GLOBALS["xhtml_dir"]."/".$this->template."/footer.inc.php");
		}
		else
		{
			$this->error(5);
		}
	}
	
}
?>